﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.command;
using l1cs.server.model.Instance;
using l1cs.server.model.skill;
using l1cs.server.model;
using l1cs.server.serverpackets;

namespace l1cs.server.command.executor
{
    public class L1HpBar //: L1CommandExecutor
    {
        private static Logger _log = Logger.getLogger( typeof( L1HpBar ).FullName );

        private L1HpBar()
        {
        }

        //public static L1CommandExecutor getInstance()
        //{
        //    return new L1HpBar();
        //}

        public void execute( L1PcInstance pc, String cmdName, String arg )
        {
            if ( string.Compare( arg, "on", true ) == 0 )
            {
                pc.setSkillEffect( L1SkillId.GMSTATUS_HPBAR, 0 );
            }
            else if ( string.Compare( arg, "off", true ) == 0 )
            {
                pc.removeSkillEffect( L1SkillId.GMSTATUS_HPBAR );

                foreach ( L1Object obj in pc.getKnownObjects() )
                {
                    if ( isHpBarTarget( obj ) )
                    {
                        pc.sendPackets( new S_HPMeter( obj.getId(), 0xFF ) );
                    }
                }
            }
            else
            {
                pc.sendPackets( new S_SystemMessage( cmdName + " on|off と入力してください。" ) );
            }
        }

        public static bool isHpBarTarget( L1Object obj )
        {
            if ( obj is L1MonsterInstance )
            {
                return true;
            }
            if ( obj is L1PcInstance )
            {
                return true;
            }
            if ( obj is L1SummonInstance )
            {
                return true;
            }
            if ( obj is L1PetInstance )
            {
                return true;
            }
            return false;
        }
    }
}
